
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
request.setAttribute("decorator", "none");
response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", 0);
%>

<%-- 导入面包屑 --%>
<jsp:include page="../common/nav.jsp"></jsp:include>

<div class="wrapper wrapper-content animated fadeInRight">

	<%-- 导入提示信息框 --%>
    <c:if test="${hint!=null&&hint!=''}">
   		<jsp:include page="../common/alert/alert.jsp">
   			<jsp:param value="${hint}" name="alertType"/>
   			<jsp:param value="${alertMessage}" name="alertMessage"/>
   		</jsp:include>
    </c:if>

	<div class="row">
		<div class="col-lg-12">
			<div class="ibox ">
				<div class="ibox-title btn-success btn-outline panel-success collapse-link" title="展开/收起">
					<h5>工作中心&nbsp;<span style="color: black;">（<i class="fa fa-tag"></i>${requestScope.approveStatusMap[requestScope.prodWorkCenter.approveStatus]}）</span></h5>
					<div class="ibox-tools">
						<i class="fa fa-chevron-up"></i> 
					</div>
				</div>

				<div class="ibox-content border-bottom" style="padding-bottom: 0px;">
					<form id="form" action="web/prodWorkCenter/editProdWorkCenter" method="post">
						<div class="form-group  row">
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>工作中心编码</strong></label>
							<div class="col-sm-4">
								<input id="workCenterCode" name="workCenterCode" type="text" class="form-control" value="${requestScope.prodWorkCenter.workCenterCode}">
							</div>
							
							<label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>工作中心名称</strong></label>
							<div class="col-sm-4">
								<input id="workCenterName" name="workCenterName" type="text" class="form-control" value="${requestScope.prodWorkCenter.workCenterName}">
							</div>
						</div>
						<div class="hr-line-dashed"></div>
						
						
						<div class="form-group row">
	                        <label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>工作中心类型</strong></label>
	
	                        <div class="col-sm-4">
	                        <select class="form-control" name="workCenterType" id="workCenterType">
	                        	<c:forEach items="${requestScope.workCenterTypeMap}" var="workCenterType">
	                        		<option value="${workCenterType.key}">${workCenterType.value}</option>
	                        	</c:forEach>
	                        </select>
	                        </div>

	                        <label class="col-sm-2 col-form-label"><strong>班次</strong></label>
	
	                        <div class="col-sm-4">
	                        <select class="select2 form-control" name="workSchedule" id="workSchedule">
	                        	<option value="" selected="selected">请选择...</option>
	                        	<c:forEach items="${requestScope.workScheduleMap}" var="workSchedule">
	                        		<option value="${workSchedule.key}">${workSchedule.value}</option>
	                        	</c:forEach>
	                        </select>
	                        </div>
	                    </div>
	                    <div class="hr-line-dashed"></div>
	                    
						<div class="form-group row">
	                        <label class="col-sm-2 col-form-label"><span class="text-danger">*</span><strong>状态</strong></label>
	                        <div class="col-sm-4">
		                        <select class="form-control" name="status" id="status">
		                            <option value="Y" selected="selected">有效</option>
		                            <option value="N">无效</option>
		                        </select>
	                        </div>
	                    </div>
	                    <div class="hr-line-dashed"></div>

						<div class="form-group row">
							<div class="col-sm-12 col-sm-offset-2 text-right">
								<button class="btn btn-white btn-lg" type="button" onclick="window.location.href='web/prodWorkCenter/getProdWorkCenterList'">返回</button>&nbsp;
								<c:if test="${param.workCenterCode==null||param.workCenterCode==''||requestScope.prodWorkCenter.approveStatus=='UNSUBMIT'||requestScope.prodWorkCenter.approveStatus=='REJECT' }">
									<button class="ladda-button ladda-button-demo btn btn-success btn-lg" data-style="expand-right">&nbsp;&nbsp;保存&nbsp;&nbsp;<i class="fa fa-save"></i></button>
								</c:if>
								
								<c:if test="${param.workCenterCode!=null&&param.workCenterCode!=''}">
									<c:if test="${requestScope.prodWorkCenter.approveStatus=='UNSUBMIT'||requestScope.prodWorkCenter.approveStatus=='REJECT' }">
										<button class="btn btn-primary btn-lg" type="button" onclick="window.location.href='web/prodWorkCenter/updateApproveStatus?code=${requestScope.prodWorkCenter.workCenterCode}&approveStatus=SUBMIT'">&nbsp;&nbsp;提交&nbsp;&nbsp;<i class="fa fa-arrow-circle-right"></i></button>&nbsp;
									</c:if>
									<c:if test="${requestScope.prodWorkCenter.approveStatus=='SUBMIT' }">
										<button class="btn btn-warning btn-lg btn-redragon-approve" type="button" onclick="approveData()">&nbsp;&nbsp;审核通过&nbsp;&nbsp;<i class="fa fa-check-circle"></i></button>&nbsp;
										<button class="btn btn-danger btn-lg btn-redragon-approve" type="button" onclick="window.location.href='web/prodWorkCenter/updateApproveStatus?code=${requestScope.prodWorkCenter.workCenterCode}&approveStatus=REJECT'">&nbsp;&nbsp;驳回&nbsp;&nbsp;<i class="fa fa-times-circle"></i></button>&nbsp;
									</c:if>
									<c:if test="${requestScope.prodWorkCenter.approveStatus=='APPROVE' }">
										<button class="btn btn-success btn-lg" type="button" onclick="alterData()">&nbsp;&nbsp;变更&nbsp;&nbsp;<i class="fa fa-retweet"></i></button>&nbsp;
									</c:if>
								</c:if>
							</div>
						</div>
						
						<input type="hidden" id="workCenterId" name="workCenterId" value="${requestScope.prodWorkCenter.workCenterId}">
						<input type="hidden" name="createdDate" value="${requestScope.prodWorkCenter.createdDate}">
						<input type="hidden" name="createdBy" value="${requestScope.prodWorkCenter.createdBy}">
					</form>
				</div>

				<!-- tab 开始 -->
				<div class="row">
					<div class="col-lg-12">
						<div class="ibox ">
							<div class="ibox-title btn-info btn-outline panel-info">
								<h5>资源分配行</h5>
								<div class="ibox-tools">
								</div>
							</div>

							<div class="ibox-content border-bottom" style="padding-bottom: 0px;">
								<div class="tabs-container">
									<ul class="nav nav-tabs">
										<li><a class="nav-link active" data-toggle="tab" href="#ctab" onclick="getLineTab('${requestScope.prodWorkCenter.workCenterCode}')">行信息</a></li>
									</ul>
									<div id="tabDiv" class="tab-content">
									</div>
								</div>
							</div>
							
						</div>
					</div>
				</div>
				<!-- tab 结束 -->
				
			</div>
		</div>
	</div>
</div>

<!-- select2 -->
<script src="js/plugins/select2/select2.full.min.js"></script>

<script>
	$(document).ready(function() {
		//初始化status
		if("${requestScope.prodWorkCenter.status}"!=""){
			$("#status").val("${requestScope.prodWorkCenter.status}");
		}
		//初始化workCenterType
		if("${requestScope.prodWorkCenter.workCenterType}"!=""){
			$("#workCenterType").val("${requestScope.prodWorkCenter.workCenterType}");
		}
		//初始化workSchedule
		if("${requestScope.prodWorkCenter.workSchedule}"!=""){
			$("#workSchedule").val("${requestScope.prodWorkCenter.workSchedule}");
		}
		
		//初始化workCenterCode只读
		if("${requestScope.prodWorkCenter.workCenterCode}"!=""){
			$("#workCenterCode").prop("readonly", true);
		}
	
		//初始化select2
		$('.select2').select2({width: "100%"});
		
		
		//表单提交
		var l = $('.ladda-button-demo').ladda();

		l.click(function() {
			$("#form").valid();
			//l.ladda('stop');
		});

		$("#form").validate({
			rules : {
				workCenterCode : {
					required : true,
					isCode : true,
				},
				workCenterName : {
					required : true,
				},
				workCenterType : {
					required : true,
				},
				workSchedule : {
					required : true,
				},
			},
			submitHandler: function(form) {
				l.ladda('start');
		        form.submit();
		    }
		});
		
		//初始化tab
		getLineTab("${requestScope.prodWorkCenter.workCenterCode}");
	});
	
	
	//获取行tab
	function getLineTab(code){
		$.ajax({
			type: "post",
			url: "web/prodWorkCenterResource/getProdWorkCenterResourceList",
			data: {"workCenterCode": code},
			async: false,
			dataType: "html",
			cache: false,
			success: function(data){
				if(data!=""){
					$("#tabDiv").html(data);
					$("#ctab").addClass("active");
					//隐藏保存按钮
					if(($("#workCenterId").val()!=null&&$("#workCenterId").val()!=""&&"${requestScope.prodWorkCenter.approveStatus}"!="UNSUBMIT"&&"${requestScope.prodWorkCenter.approveStatus}"!="REJECT")||$("#workCenterId").val()==null||$("#workCenterId").val()==""){
						$("#tabDiv .btn").hide();
					}
					initControlAuth();
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				redragonJS.alert(textStatus);
			}
		});
	}
	
	
	//审批通过
	function approveData(){
		redragonJS.confirm("确认审批通过？", function(){
			window.location.href='web/prodWorkCenter/updateApproveStatus?code=${requestScope.prodWorkCenter.workCenterCode}&approveStatus=APPROVE';
		});
	}
	
	//数据变更
	function alterData(){
		redragonJS.confirm("确认变更数据？数据变更可能会影响到已有的业务！", function(){
			window.location.href='web/prodWorkCenter/updateApproveStatus?code=${requestScope.prodWorkCenter.workCenterCode}&approveStatus=UNSUBMIT';
		});
	}
	
</script>